﻿namespace CocoaAni.Net.WebSockets.Server.SendAdapters;

public interface IMessageSendAdapter
{
    public Type TargetType { get; }

    public Task SendAsync(WebSocketContext context, object target, CancellationToken cancellationToken = default);
}

public abstract class MessageSendMessageAdapter<T> : IMessageSendAdapter
{
    public Type TargetType { get; }

    protected MessageSendMessageAdapter()
    {
        TargetType = typeof(T);
    }

    public abstract Task SendAsync(WebSocketContext context, T target, CancellationToken cancellationToken = default);

    public Task SendAsync(WebSocketContext context, object target, CancellationToken cancellationToken = default)
    {
        return SendAsync(context, (T)target, cancellationToken);
    }
}